<?php if(!defined('IN_FIRADIO')) {header('HTTP/1.1 403 Forbidden');exit('<h1>Access Denied</h1>');}?>
<?php $GLOBALS['script'][] = function() {?><script>
vue.methods.postapi = function () {
    const that = this;
    that.init();
    that.ApiPost('/panel/ua/link_list.php', that.form).then(function (data) {
        vue.data.apidata = data.data;
    }, function (data) {
    });
};
vue.methods.postapi_add = function () {
    const that = this;
    that.ApiPost('/panel/ua/link_add.php', that.form_add).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
    });
};
vue.methods.postapi_save = function (row) {
    const that = this;
    that.ApiPost('/panel/ua/link_save.php', row).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
    });
};
vue.methods.postapi_del = function () {
    const that = this;
    const del_ids = [];
    for (var key in that.apidata.rows) {
        const row = that.apidata.rows[key];
        if (row.del) del_ids.push(row.id);
    }
    if (del_ids.length <= 0) {
        alert('请先选择要删除的记录');
        return;
    }
    if (!confirm("确定要删除这" + del_ids.length + "条记录吗？")) return;
    that.ApiPost('/panel/ua/link_del.php', {'del_ids':del_ids}).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
        //console.log('reject:', data);
    });
};
vue.methods.link_clear = function (clear_id) {
    if (!confirm("确定要清空 id=" + clear_id + " 的链接吗？")) return;
    const that = this;
    that.ApiPost('/panel/ua/link_clear.php', {'clear_id': clear_id}).then(function (data) {
        vue.methods.postapi();
    }, function (data) {
    });
};
vue.methods.init = function () {
    vue.data.disabled = false;
    vue.data.apidata = {};
    vue.data.apidata.rows = [];
    vue.data.form_add = {};
    vue.data.form_add.url = '';
    vue.data.form_add.timeout = 1;
};
vue.methods.init();
vue.mounted = function () {
    vue.methods.postapi();
};
</script><?php }?>

<!-- Custom Tabs -->
<form v-on:submit="postapi" onsubmit="return false" :disabled="disabled">
<div class="nav-tabs-custom">

    <table class="table table-bordered table-striped dataTable">
        <tr align="center">
            <td>ID</td>
            <td>链接名称</td>
            <td style="width:80px;">获取数量</td>
            <td style="width:80px;">附加随机值</td>
            <td style="min-width:400px;">获取URL</td>
            <td>模板数</td>
            <td>删除</td>
        </tr>
        <tr v-for="row in apidata.rows" align="center">
            <td>{{row.id}}</td>
            <td><input style="width:100%" v-on:change="postapi_save(row)" v-model="row.title" /></td>
            <td><input style="width:100%" v-on:change="postapi_save(row)" v-model="row.count" maxlength="5" /></td>
            <td><label><input type="checkbox" v-on:change="postapi_save(row)" v-model="row.is_addrandstr" />启用</label></td>
            <td><input style="width:100%" :value="'http://192.168.100.181:81/ua/list.php?id='+row.id" readonly /></td>
            <td>
                <span v-if="row.sCard">
                    {{row.sCard}}
                    <button class="btn btn-default btn-xs" type="button" v-on:click="link_clear(row.id)">清空</button>
                </span>
                <span v-else>0</span>
            </td>
            <td><label><input type="checkbox" v-model="row.del" />删除</label></td>
        </tr>
        <tr align="center">
            <td>新增</td>
            <td><input style="width:100%" v-on:change="postapi_add" v-model="form_add.title" required /></td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td>-</td>
            <td><button class="btn btn-default btn-xs" type="button" v-on:click="postapi_del()">删除</button></td>
        </tr>
    </table>
</div>
</form>
